package com.tuo51.evaluate.repositories.evaluatev2;

import com.tuo51.evaluate.domain.evaluatingV2.EvaluateV2RecordDimensionScore;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface EvaluateV2RecordDimensionScoreRepository extends JpaRepository<EvaluateV2RecordDimensionScore, String> {

    EvaluateV2RecordDimensionScore findOneByRecordIdAndDimensionId(String recordId, String dimensionId);

    @Query(value = "SELECT s.* FROM `tb_evaluate_dimension_score` s " +
            " LEFT JOIN `tb_evaluate_dimension` d on d.`id` = s.`dimensionId` " +
            " WHERE s.`recordId` = :recordId " +
            " ORDER BY d.`code` ", nativeQuery = true)
    List<EvaluateV2RecordDimensionScore> findAllByRecordIdOrderByCreated(@Param("recordId") String recordId);

}
